home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DBSHOW.CPP < prev    next >
C/C++ Source or Header  |  1993-08-23  |  5KB  |  176 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    dbshow.cpp
  5. //   Title:    Application Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains the program entry point for
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <dbase.hpp>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //    Stack size
  45. //----------------------------------------------------------------------------
  46. #if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
  47. unsigned _stklen = 0x4000;
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //    Globals
  53. //----------------------------------------------------------------------------
  54.  
  55. //
  56. // A useless string which is simply embedded in the executable.
  57. //
  58. PSZ __pszCredits__ = "Written by John M Weeder, 1993";
  59.  
  60.  
  61. //
  62. //    This should contain a program description which will be displayed as
  63. //    part of the program's help text.
  64. //
  65. static PCSZ pcszDescription =
  66.     "This program displays the contents of a dBase file.";
  67.  
  68. //
  69. //    Program command line options
  70. //
  71. static LONG lStart = 1;
  72. static LONG lEnd = -1;
  73. static LONG lLength = -1;
  74. static CHAR szInput[MAX_PATH];
  75. static BS_CMDOPT acmdopt[] =
  76.     {
  77.     { "BEGIN",         (PVOID)&lStart,     CMDOPT_NUMERIC,        "First record to display."},
  78.     { "END",         (PVOID)&lEnd,         CMDOPT_NUMERIC,        "Last record to display."},
  79.     { "LENGTH",     (PVOID)&lLength,     CMDOPT_NUMERIC,        "Number of records to display."},
  80.     { "filename",     (PVOID)szInput,     CMDOPT_FILESPECR(80),"File name."},
  81.     BS_CMDOPT_NULL,
  82.     };
  83.  
  84.  
  85. //----------------------------------------------------------------------------
  86. //   Description:    
  87. //    Parameters:
  88. //       Returns:    TRUE if successful.
  89. //----------------------------------------------------------------------------
  90. static VOID FN_L Display(RDB_DBASE db)
  91. {
  92.     SIZET cFields = db.Fields();
  93.  
  94.     LONG FN_M Record();
  95.     Output("Record # %ld:\n", db.Record());
  96.     for (SIZET i = 1; i <= cFields; ++i)
  97.         {
  98.         DB_FLD fld(&db, i);
  99.  
  100.         Output("  %2d) %-15.15s %c %3d : %-45.45s\n",
  101.             i, fld.Name(), fld.Type(), fld.Len(),
  102.             (fld.Type() == 'M' ? "*** Memo Field ***": (PCSZ)fld));
  103.         }
  104.     Output("\n");
  105.     return ;
  106. }
  107.  
  108.  
  109. //----------------------------------------------------------------------------
  110. //   Description:    
  111. //    Parameters:
  112. //       Returns:    TRUE if successful.
  113. //----------------------------------------------------------------------------
  114. static SHORT FN_L Process(void)
  115. {
  116.     DB_DBASE db;
  117.  
  118.     if (!db.Open(szInput))
  119.         return FALSE;
  120.  
  121.     LONG lRecords = db.Records();
  122.  
  123.     Output("Opened '%s' (%ld records)\n", szInput, lRecords);
  124.  
  125.     if (lRecords == 0)
  126.         return TRUE;
  127.     if (lStart < 1)
  128.         lStart = 1;
  129.     if (lStart > lRecords)
  130.         lStart = lRecords;
  131.     if (lLength > 0)
  132.         lEnd = lStart + lLength - 1;
  133.     if (lEnd > lRecords || lEnd < lStart)
  134.         lEnd = lRecords;
  135.  
  136.     for (; lStart <= lEnd; ++lStart)
  137.         {
  138.         if (!db.Go(lStart))
  139.             return FALSE;
  140.  
  141.         Display(db);
  142.  
  143.         db.Unlock();
  144.         }
  145.     return TRUE;
  146. }
  147.  
  148.  
  149. //----------------------------------------------------------------------------
  150. //   Description:    main() - Program entry point
  151. //    Parameters:    Standard C parameters
  152. //       Returns:    DOS return code.
  153. //----------------------------------------------------------------------------
  154. int main(int argc, char **argv)
  155. {
  156. static BS_CFG cfg = CFG_DFT;
  157.     BOOL fResult;
  158.  
  159.     //
  160.     //    Initialize base library
  161.     //
  162.     BaseLibraryInitialize(argc, argv, &cfg);
  163.     BaseTitle("$Revision:  93.1  $", __DATE__, __TIME__, "dBase File Viewer Utility");
  164.     if (!BaseTitleHelp(acmdopt, pcszDescription))
  165.         return 99;
  166.     if (DB_DBASE::Start())
  167.         {
  168.         fResult = Process();
  169.         DB_DBASE::Terminate();
  170.         }
  171.     Output(fResult ? "Success.\n": "Failed\n");
  172.     return fResult ? 0: 99;
  173. }
  174. //----------------------------------------------------------------------------
  175. //------------------------------- End of File --------------------------------
  176. //----------------------------------------------------------------------------